home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / DataRelay / frmDataRelay.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  27.8 KB  |  677 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDataRelay 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "vbData Relay"
  5.    ClientHeight    =   6255
  6.    ClientLeft      =   645
  7.    ClientTop       =   930
  8.    ClientWidth     =   7755
  9.    Icon            =   "frmDataRelay.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   6255
  14.    ScaleWidth      =   7755
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Frame Frame5 
  17.       Caption         =   "Connection Information"
  18.       Height          =   2715
  19.       Left            =   3240
  20.       TabIndex        =   23
  21.       Top             =   960
  22.       Width           =   4455
  23.       Begin VB.TextBox txtInfo 
  24.          BackColor       =   &H8000000F&
  25.          Height          =   1935
  26.          Left            =   120
  27.          MultiLine       =   -1  'True
  28.          ScrollBars      =   2  'Vertical
  29.          TabIndex        =   26
  30.          Top             =   660
  31.          Width           =   4155
  32.       End
  33.       Begin VB.ComboBox cboInfoTarget 
  34.          Height          =   315
  35.          Left            =   1380
  36.          Style           =   2  'Dropdown List
  37.          TabIndex        =   25
  38.          Top             =   240
  39.          Width           =   2655
  40.       End
  41.       Begin VB.Label Label1 
  42.          Alignment       =   1  'Right Justify
  43.          BackStyle       =   0  'Transparent
  44.          Caption         =   "Info Target: "
  45.          Height          =   195
  46.          Index           =   6
  47.          Left            =   300
  48.          TabIndex        =   24
  49.          Top             =   300
  50.          Width           =   1035
  51.       End
  52.    End
  53.    Begin VB.Timer tmrReceivedData 
  54.       Interval        =   1
  55.       Left            =   180
  56.       Top             =   3060
  57.    End
  58.    Begin VB.Timer tmrSendData 
  59.       Interval        =   1
  60.       Left            =   720
  61.       Top             =   3060
  62.    End
  63.    Begin VB.Frame Frame4 
  64.       Caption         =   "Statistics"
  65.       Height          =   915
  66.       Left            =   60
  67.       TabIndex        =   18
  68.       Top             =   2760
  69.       Width           =   3135
  70.       Begin VB.Label lblReceive 
  71.          BackStyle       =   0  'Transparent
  72.          Caption         =   "0.0"
  73.          Height          =   195
  74.          Left            =   2160
  75.          TabIndex        =   22
  76.          Top             =   480
  77.          Width           =   855
  78.       End
  79.       Begin VB.Label lblSendRate 
  80.          BackStyle       =   0  'Transparent
  81.          Caption         =   "0.0"
  82.          Height          =   195
  83.          Left            =   2160
  84.          TabIndex        =   21
  85.          Top             =   240
  86.          Width           =   795
  87.       End
  88.       Begin VB.Label Label1 
  89.          Alignment       =   1  'Right Justify
  90.          BackStyle       =   0  'Transparent
  91.          Caption         =   "Received Rate (bytes/sec) :"
  92.          Height          =   195
  93.          Index           =   8
  94.          Left            =   60
  95.          TabIndex        =   20
  96.          Top             =   480
  97.          Width           =   2055
  98.       End
  99.       Begin VB.Label Label1 
  100.          Alignment       =   1  'Right Justify
  101.          BackStyle       =   0  'Transparent
  102.          Caption         =   "Send Rate (bytes/sec) :"
  103.          Height          =   195
  104.          Index           =   7
  105.          Left            =   60
  106.          TabIndex        =   19
  107.          Top             =   240
  108.          Width           =   2055
  109.       End
  110.    End
  111.    Begin VB.Frame Frame3 
  112.       Caption         =   "Send"
  113.       Height          =   1755
  114.       Left            =   60
  115.       TabIndex        =   9
  116.       Top             =   960
  117.       Width           =   3135
  118.       Begin VB.ComboBox cboTimeout 
  119.          Height          =   315
  120.          Left            =   1200
  121.          Style           =   2  'Dropdown List
  122.          TabIndex        =   17
  123.          Top             =   1320
  124.          Width           =   1815
  125.       End
  126.       Begin VB.ComboBox cboTarget 
  127.          Height          =   315
  128.          Left            =   1200
  129.          Style           =   2  'Dropdown List
  130.          TabIndex        =   16
  131.          Top             =   240
  132.          Width           =   1815
  133.       End
  134.       Begin VB.ComboBox cboSize 
  135.          Height          =   315
  136.          Left            =   1200
  137.          Style           =   2  'Dropdown List
  138.          TabIndex        =   15
  139.          Top             =   600
  140.          Width           =   1815
  141.       End
  142.       Begin VB.ComboBox cboRate 
  143.          Height          =   315
  144.          Left            =   1200
  145.          Style           =   2  'Dropdown List
  146.          TabIndex        =   14
  147.          Top             =   960
  148.          Width           =   1815
  149.       End
  150.       Begin VB.Label Label1 
  151.          BackStyle       =   0  'Transparent
  152.          Caption         =   "Timeout (ms) :"
  153.          Height          =   195
  154.          Index           =   5
  155.          Left            =   120
  156.          TabIndex        =   13
  157.          Top             =   1380
  158.          Width           =   1035
  159.       End
  160.       Begin VB.Label Label1 
  161.          Alignment       =   1  'Right Justify
  162.          BackStyle       =   0  'Transparent
  163.          Caption         =   "Target :"
  164.          Height          =   195
  165.          Index           =   4
  166.          Left            =   120
  167.          TabIndex        =   12
  168.          Top             =   300
  169.          Width           =   1035
  170.       End
  171.       Begin VB.Label Label1 
  172.          Alignment       =   1  'Right Justify
  173.          BackStyle       =   0  'Transparent
  174.          Caption         =   "Size (bytes) :"
  175.          Height          =   195
  176.          Index           =   3
  177.          Left            =   120
  178.          TabIndex        =   11
  179.          Top             =   660
  180.          Width           =   1035
  181.       End
  182.       Begin VB.Label Label1 
  183.          Alignment       =   1  'Right Justify
  184.          BackStyle       =   0  'Transparent
  185.          Caption         =   "Rate (ms) :"
  186.          Height          =   195
  187.          Index           =   2
  188.          Left            =   120
  189.          TabIndex        =   10
  190.          Top             =   1020
  191.          Width           =   1035
  192.       End
  193.    End
  194.    Begin VB.Frame Frame2 
  195.       Caption         =   "Log"
  196.       Height          =   2415
  197.       Left            =   60
  198.       TabIndex        =   7
  199.       Top             =   3720
  200.       Width           =   7635
  201.       Begin VB.TextBox txtLog 
  202.          BackColor       =   &H8000000F&
  203.          Height          =   2055
  204.          Left            =   120
  205.          MultiLine       =   -1  'True
  206.          ScrollBars      =   3  'Both
  207.          TabIndex        =   8
  208.          Top             =   240
  209.          Width           =   7395
  210.       End
  211.    End
  212.    Begin VB.Frame Frame1 
  213.       Caption         =   "Game Status"
  214.       Height          =   855
  215.       Left            =   60
  216.       TabIndex        =   0
  217.       Top             =   60
  218.       Width           =   7635
  219.       Begin VB.CommandButton cmdExit 
  220.          Cancel          =   -1  'True
  221.          Caption         =   "Exit"
  222.          Height          =   375
  223.          Left            =   5880
  224.          TabIndex        =   6
  225.          Top             =   300
  226.          Width           =   1575
  227.       End
  228.       Begin VB.CommandButton cmdSend 
  229.          Caption         =   "Push to send"
  230.          Enabled         =   0   'False
  231.          Height          =   375
  232.          Left            =   4200
  233.          TabIndex        =   5
  234.          Top             =   300
  235.          Width           =   1575
  236.       End
  237.       Begin VB.Label lblPlayers 
  238.          BackStyle       =   0  'Transparent
  239.          Caption         =   "0"
  240.          Height          =   255
  241.          Left            =   2340
  242.          TabIndex        =   4
  243.          Top             =   480
  244.          Width           =   195
  245.       End
  246.       Begin VB.Label lblPlayer 
  247.          BackStyle       =   0  'Transparent
  248.          Caption         =   "TestPlayer"
  249.          Height          =   255
  250.          Left            =   1560
  251.          TabIndex        =   3
  252.          Top             =   240
  253.          Width           =   1635
  254.       End
  255.       Begin VB.Label Label1 
  256.          BackStyle       =   0  'Transparent
  257.          Caption         =   "Number of Players in session:"
  258.          Height          =   195
  259.          Index           =   1
  260.          Left            =   120
  261.          TabIndex        =   2
  262.          Top             =   480
  263.          Width           =   2175
  264.       End
  265.       Begin VB.Label Label1 
  266.          BackStyle       =   0  'Transparent
  267.          Caption         =   "Local Player Name:"
  268.          Height          =   195
  269.          Index           =   0
  270.          Left            =   120
  271.          TabIndex        =   1
  272.          Top             =   240
  273.          Width           =   1455
  274.       End
  275.    End
  276. Attribute VB_Name = "frmDataRelay"
  277. Attribute VB_GlobalNameSpace = False
  278. Attribute VB_Creatable = False
  279. Attribute VB_PredeclaredId = True
  280. Attribute VB_Exposed = False
  281. Option Explicit
  282. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  283. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  284. '  File:       frmDataRelay.frm
  285. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  286. 'Declare for timeGetTime
  287. Private Declare Function timeGetTime Lib "winmm.dll" () As Long
  288. Implements DirectPlay8Event
  289. Private Const mlTextSize As Long = 32768
  290. Private Type PacketInfo
  291.     lPacketID As Long
  292.     lDataSize As Long
  293. End Type
  294. Private mfSending As Boolean
  295. Private mlRate As Long
  296. Private mlToPlayerID As Long
  297. Private mlTimeOut As Long
  298. Private mlSize As Long
  299. Private mlSending As Long
  300. Private mlLastSendTime As Long
  301. Private mlDataReceived As Long
  302. Private mlDataSent As Long
  303. Private mfInSend As Boolean
  304. Private mfInReceive As Boolean
  305. Private moByte() As Byte, moBuf() As Byte 'DirectPlayBuffer
  306. Private moReceived As New Collection
  307. Private Sub cmdExit_Click()
  308.     'We're done, unload
  309.     Unload Me
  310. End Sub
  311. Private Sub cmdSend_Click()
  312.     If mfSending Then
  313.         'Stop sending now
  314.         cmdSend.Caption = "Push to send"
  315.     Else
  316.         'Start sending now
  317.         cmdSend.Caption = "Push to stop"
  318.         ReadCombos
  319.     End If
  320.     EnableComboUI mfSending
  321.     mfSending = Not mfSending
  322. End Sub
  323. Private Sub Form_Load()
  324.     'First lets populate our combo boxes
  325.     PopulateBoxes
  326.     'Here we will init our DPlay objects
  327.     InitDPlay
  328.     'Now we can create a new Connection Form (which will also be our message pump)
  329.     Set DPlayEventsForm = New DPlayConnect
  330.     'Start the connection form (it will either create or join a session)
  331.     If Not DPlayEventsForm.StartConnectWizard(dx, dpp, AppGuid, 20, Me) Then
  332.         Cleanup
  333.         End
  334.     Else 'We did choose to play a game
  335.         gsUserName = DPlayEventsForm.UserName
  336.         lblPlayer.Caption = gsUserName
  337.         If DPlayEventsForm.IsHost Then Me.Caption = Me.Caption & " (HOST)"
  338.     End If
  339. End Sub
  340. Private Sub Form_Unload(Cancel As Integer)
  341.     Me.Hide
  342.     'Here we need to turn off our timers
  343.     If mfSending Then cmdSend_Click
  344.     mfSending = False
  345.     Do While moReceived.Count > 0
  346.         DPlayEventsForm.DoSleep 50
  347.     Loop
  348.     tmrReceivedData.Enabled = False
  349.     tmrSendData.Enabled = False
  350.     Cleanup
  351. End Sub
  352. Private Sub PopulateBoxes()
  353.     With cboTarget
  354.         .AddItem "Everyone"
  355.         .ListIndex = 0
  356.     End With
  357.     With cboRate
  358.         .AddItem "1000"
  359.         .AddItem "500"
  360.         .AddItem "250"
  361.         .AddItem "100"
  362.         .AddItem "50"
  363.         .ListIndex = 0
  364.     End With
  365.     With cboSize
  366.         .AddItem "512"
  367.         .AddItem "256"
  368.         .AddItem "128"
  369.         .AddItem "64"
  370.         .AddItem "32"
  371.         .AddItem "16"
  372.         .ListIndex = 0
  373.     End With
  374.     With cboTimeout
  375.         .AddItem "5"
  376.         .AddItem "10"
  377.         .AddItem "20"
  378.         .AddItem "50"
  379.         .AddItem "100"
  380.         .AddItem "250"
  381.         .AddItem "500"
  382.         .ListIndex = 0
  383.     End With
  384.     With cboInfoTarget
  385.         .AddItem "None"
  386.         .ListIndex = 0
  387.     End With
  388. End Sub
  389. Private Sub EnableComboUI(ByVal fEnable As Boolean)
  390.     cboRate.Enabled = fEnable
  391.     cboTarget.Enabled = fEnable
  392.     cboTimeout.Enabled = fEnable
  393.     cboSize.Enabled = fEnable
  394. End Sub
  395. Private Sub ReadCombos()
  396.     mlRate = CLng(cboRate.List(cboRate.ListIndex))
  397.     mlSize = CLng(cboSize.List(cboSize.ListIndex))
  398.     mlTimeOut = CLng(cboTimeout.List(cboTimeout.ListIndex))
  399.     mlToPlayerID = cboTarget.ItemData(cboTarget.ListIndex) 'The ItemData for everyone is 0
  400. End Sub
  401. Private Sub AppendText(ByVal sString As String)
  402.     'Update the chat window first
  403.     txtLog.Text = txtLog.Text & sString & vbCrLf
  404.     'Now limit the text in the window to be 16k
  405.     If Len(txtLog.Text) > mlTextSize Then
  406.         txtLog.Text = Right$(txtLog.Text, mlTextSize)
  407.     End If
  408.     'Autoscroll the text
  409.     txtLog.SelStart = Len(txtLog.Text)
  410. End Sub
  411. Private Function GetName(ByVal lID As Long) As String
  412.     Dim lCount As Long
  413.     'Here we will get the name of the player sending us info from the combo box
  414.     GetName = vbNullString
  415.     For lCount = 0 To cboTarget.ListCount - 1
  416.         If cboTarget.ItemData(lCount) = lID Then 'This is the player
  417.             GetName = cboTarget.List(lCount)
  418.             Exit For
  419.         End If
  420.     Next
  421. End Function
  422. Private Sub tmrReceivedData_Timer()
  423.     Dim oBuf() As Byte, lNewMsg As Long, lNewOffset As Long
  424.     Dim sItems() As String, oPacket As PacketInfo
  425.     'If mfInReceive Then Exit Sub
  426.     'We use a timer control here because we don't want to ever
  427.     'block DirectPlay.
  428.     Do While moReceived.Count > 0
  429.         mfInReceive = True
  430.         sItems = Split(moReceived.Item(1), ";")
  431.         AppendText "Received packet #" & sItems(1) & " from " & GetName(CLng(sItems(0))) & " - Size:" & sItems(2)
  432.         'now let this user know we received the packet
  433.         lNewMsg = MSG_PacketReceive
  434.         lNewOffset = NewBuffer(oBuf)
  435.         AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffset
  436.         oPacket.lDataSize = CLng(sItems(2))
  437.         oPacket.lPacketID = CLng(sItems(1))
  438.         mlDataReceived = mlDataReceived + oPacket.lDataSize
  439.         AddDataToBuffer oBuf, oPacket, LenB(oPacket), lNewOffset
  440.         'We don't care to see the receive callback.
  441.         dpp.SendTo CLng(sItems(0)), oBuf, mlTimeOut, DPNSEND_NOLOOPBACK
  442.         Erase oBuf
  443.         moReceived.Remove 1
  444.     Loop
  445.     mfInReceive = False
  446. End Sub
  447. Private Sub tmrSendData_Timer()
  448.     Dim lMsg As Long, lOffset As Long
  449.     Dim oPacket As PacketInfo
  450.     'We use a timer control here because we don't want to ever
  451.     'block DirectPlay.
  452.     'If mfInSend Then Exit Sub
  453.     If mfSending Then 'We are sending
  454.         If Abs(timeGetTime - mlLastSendTime) > mlRate Then 'We should send another packet now
  455.             mfInSend = True
  456.             lMsg = MSG_GamePacket
  457.             lOffset = NewBuffer(moBuf)
  458.             AddDataToBuffer moBuf, lMsg, LenB(lMsg), lOffset
  459.             mlSending = mlSending + 1
  460.             oPacket.lPacketID = mlSending
  461.             oPacket.lDataSize = mlSize
  462.             mlDataSent = mlDataSent + mlSize
  463.             AddDataToBuffer moBuf, oPacket, LenB(oPacket), lOffset
  464.             ReDim moByte(mlSize)
  465.             AddDataToBuffer moBuf, moByte(0), mlSize, lOffset
  466.             'We will send the NOLOOPBACK flag so we do not get a 'Receive' event for
  467.             'this message.
  468.             'The NOCOPY flag tells DPlay not to copy our buffer.  We will erase the buffer in the
  469.             'SendComplete event
  470.             dpp.SendTo mlToPlayerID, moBuf, mlTimeOut, DPNSEND_NOLOOPBACK Or DPNSEND_NOCOPY
  471.             mlLastSendTime = timeGetTime
  472.         End If
  473.     End If
  474.     'Regardless of what's going on, we should update our ui
  475.     UpdateStats
  476. End Sub
  477. Private Sub UpdateStats()
  478.     Dim lNumMsgs As Long, lNumBytes As Long
  479.     Dim lCurTime As Long
  480.     Dim sText As String, dpnInfo As DPN_CONNECTION_INFO
  481.     Dim lNumMsgHigh As Long, lNumByteHigh As Long
  482.     Dim lNumMsgNormal As Long, lNumByteNormal As Long
  483.     Dim lNumMsgLow As Long, lNumByteLow As Long
  484.     Dim lDrops As Long, lSends As Long
  485.     Dim lPlayerID As Long
  486.     On Error Resume Next
  487.     Static lLastTime As Long
  488.     If lLastTime = 0 Then lLastTime = timeGetTime
  489.     lCurTime = timeGetTime
  490.     If (lCurTime - lLastTime) < 1000 Then Exit Sub 'We don't need to update more than once a second
  491.         
  492.     Dim nSecondsPassed As Single, nDataIn As Single
  493.     Dim nDataOut As Single
  494.     nSecondsPassed = (lCurTime - lLastTime) / 1000
  495.     nDataIn = mlDataReceived / nSecondsPassed
  496.     nDataOut = mlDataSent / nSecondsPassed
  497.     lLastTime = lCurTime
  498.     mlDataReceived = 0
  499.     mlDataSent = 0
  500.     lblSendRate.Caption = Format$(CStr(nDataOut), "0.0#")
  501.     lblReceive.Caption = Format$(CStr(nDataIn), "0.0#")
  502.     If cboInfoTarget.ListIndex >= 0 Then
  503.         lPlayerID = cboInfoTarget.ItemData(cboInfoTarget.ListIndex)
  504.         If lPlayerID <> 0 Then
  505.             'Update the connection info
  506.             dpnInfo = dpp.GetConnectionInfo(lPlayerID, 0)
  507.             dpp.GetSendQueueInfo lPlayerID, lNumMsgHigh, lNumByteHigh, DPNGETSENDQUEUEINFO_PRIORITY_HIGH
  508.             dpp.GetSendQueueInfo lPlayerID, lNumMsgLow, lNumByteLow, DPNGETSENDQUEUEINFO_PRIORITY_LOW
  509.             dpp.GetSendQueueInfo lPlayerID, lNumMsgNormal, lNumByteNormal, DPNGETSENDQUEUEINFO_PRIORITY_NORMAL
  510.             lDrops = dpnInfo.lPacketsDropped + dpnInfo.lPacketsRetried
  511.             lDrops = lDrops * 10000
  512.             lSends = dpnInfo.lPacketsSentGuaranteed + dpnInfo.lPacketsSentNonGuaranteed
  513.             If lSends > 0 Then lDrops = lDrops \ lSends
  514.             
  515.             sText = "Send Queue Messages High Priority=" & CStr(lNumMsgHigh) & vbCrLf
  516.             sText = sText & "Send Queue Bytes High Priority=" & CStr(lNumByteHigh) & vbCrLf
  517.             sText = sText & "Send Queue Messages Normal Priority=" & CStr(lNumMsgNormal) & vbCrLf
  518.             sText = sText & "Send Queue Bytes Normal Priority=" & CStr(lNumByteNormal) & vbCrLf
  519.             sText = sText & "Send Queue Messages Low Priority=" & CStr(lNumMsgLow) & vbCrLf
  520.             sText = sText & "Send Queue Bytes Low Priority=" & CStr(lNumByteLow) & vbCrLf
  521.             sText = sText & "Round Trip Latency MS=" & CStr(dpnInfo.lRoundTripLatencyMS) & " ms" & vbCrLf
  522.             sText = sText & "Throughput BPS=" & CStr(dpnInfo.lThroughputBPS) & vbCrLf
  523.             sText = sText & "Peak Throughput BPS=" & CStr(dpnInfo.lPeakThroughputBPS) & vbCrLf
  524.                                                                             
  525.             sText = sText & "Bytes Sent Guaranteed=" & CStr(dpnInfo.lBytesSentGuaranteed) & vbCrLf
  526.             sText = sText & "Packets Sent Guaranteed=" & CStr(dpnInfo.lPacketsSentGuaranteed) & vbCrLf
  527.             sText = sText & "Bytes Sent Non-Guaranteed=" & CStr(dpnInfo.lBytesSentNonGuaranteed) & vbCrLf
  528.             sText = sText & "Packets Sent Non-Guaranteed=" & CStr(dpnInfo.lPacketsSentNonGuaranteed) & vbCrLf
  529.                                                                             
  530.             sText = sText & "Bytes Retried Guaranteed=" & CStr(dpnInfo.lBytesRetried) & vbCrLf
  531.             sText = sText & "Packets Retried Guaranteed=" & CStr(dpnInfo.lPacketsRetried) & vbCrLf
  532.             sText = sText & "Bytes Dropped Non-Guaranteed=" & CStr(dpnInfo.lBytesDropped) & vbCrLf
  533.             sText = sText & "Packets Dropped Non-Guaranteed=" & CStr(dpnInfo.lPacketsDropped) & vbCrLf
  534.                                                                             
  535.             sText = sText & "Messages Transmitted High Priority=" & CStr(dpnInfo.lMessagesTransmittedHighPriority) & vbCrLf
  536.             sText = sText & "Messages Timed Out High Priority=" & CStr(dpnInfo.lMessagesTimedOutHighPriority) & vbCrLf
  537.             sText = sText & "Messages Transmitted Normal Priority=" & CStr(dpnInfo.lMessagesTransmittedNormalPriority) & vbCrLf
  538.             sText = sText & "Messages Timed Out Normal Priority=" & CStr(dpnInfo.lMessagesTimedOutNormalPriority) & vbCrLf
  539.             sText = sText & "Messages Transmitted Low Priority=" & CStr(dpnInfo.lMessagesTransmittedLowPriority) & vbCrLf
  540.             sText = sText & "Messages Timed Out Low Priority=" & CStr(dpnInfo.lMessagesTimedOutLowPriority) & vbCrLf
  541.                                                                             
  542.             sText = sText & "Bytes Received Guaranteed=" & CStr(dpnInfo.lBytesReceivedGuaranteed) & vbCrLf
  543.             sText = sText & "Packets Received Guaranteed=" & CStr(dpnInfo.lPacketsReceivedGuaranteed) & vbCrLf
  544.             sText = sText & "Bytes Received Non-Guaranteed=" & CStr(dpnInfo.lBytesReceivedNonGuaranteed) & vbCrLf
  545.             sText = sText & "Packets Received Non-Guaranteed=" & CStr(dpnInfo.lPacketsReceivedNonGuaranteed) & vbCrLf
  546.             sText = sText & "Messages Received=" & CStr(dpnInfo.lMessagesReceived) & vbCrLf
  547.                                                                             
  548.             sText = sText & "Loss Rate=" & CStr(lDrops \ 100) & "." & CStr(lDrops Mod 100) & vbCrLf
  549.             txtInfo.Text = sText
  550.         Else
  551.             txtInfo.Text = vbNullString
  552.         End If
  553.     End If
  554. End Sub
  555. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  556.     'VB requires that we must implement *every* member of this interface
  557. End Sub
  558. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  559.     'VB requires that we must implement *every* member of this interface
  560. End Sub
  561. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  562.     'VB requires that we must implement *every* member of this interface
  563. End Sub
  564. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  565.     If dpnotify.hResultCode <> 0 Then
  566.         'For some reason we could not connect.  All available slots must be closed.
  567.         MsgBox "Connect Failed.  Error: 0x" & CStr(Hex$(dpnotify.hResultCode)) & "  - This sample will now close.", vbOKOnly Or vbCritical, "Closing"
  568.         DPlayEventsForm.CloseForm Me
  569.     End If
  570. End Sub
  571. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  572.     'VB requires that we must implement *every* member of this interface
  573. End Sub
  574. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  575.     Dim lCount As Long
  576.     Dim dpPeer As DPN_PLAYER_INFO
  577.     'When someone joins add them to the 'Target' combo box
  578.     'and update the number of players list
  579.     dpPeer = dpp.GetPeerInfo(lPlayerID)
  580.     If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = 0 Then 'This isn't me add this user
  581.         cboTarget.AddItem dpPeer.Name
  582.         cboTarget.ItemData(cboTarget.ListCount - 1) = lPlayerID
  583.         cboInfoTarget.AddItem dpPeer.Name
  584.         cboInfoTarget.ItemData(cboInfoTarget.ListCount - 1) = lPlayerID
  585.     End If
  586.     'Update our player count,and enable the send button (if need be)
  587.     lblPlayers.Caption = CStr(cboTarget.ListCount)
  588.     cmdSend.Enabled = (cboTarget.ListCount > 1)
  589. End Sub
  590. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  591.     'VB requires that we must implement *every* member of this interface
  592. End Sub
  593. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  594.     Dim lCount As Long
  595.     Dim dpPeer As DPN_PLAYER_INFO
  596.     'Remove this player from our list
  597.     For lCount = 0 To cboTarget.ListCount - 1
  598.         If cboTarget.ItemData(lCount) = lPlayerID Then 'This is the player
  599.             cboTarget.RemoveItem lCount
  600.             Exit For
  601.         End If
  602.     Next
  603.     For lCount = 0 To cboInfoTarget.ListCount - 1
  604.         If cboInfoTarget.ItemData(lCount) = lPlayerID Then 'This is the player
  605.             cboInfoTarget.RemoveItem lCount
  606.             Exit For
  607.         End If
  608.     Next
  609.     'Update our player count,and enable the send button (if need be)
  610.     lblPlayers.Caption = CStr(cboTarget.ListCount)
  611.     cmdSend.Enabled = (cboTarget.ListCount > 1)
  612.     'If we are sending, and there is no one left to send to, or the person we were sending too left, stop sending
  613.     If (mfSending) And ((cboTarget.ListCount = 0) Or (mlToPlayerID = lPlayerID)) Then cmdSend_Click
  614.     If cboInfoTarget.ListIndex < 0 Then cboInfoTarget.ListIndex = 0
  615.     If cboTarget.ListIndex < 0 Then cboTarget.ListIndex = 0
  616. End Sub
  617. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  618.     'VB requires that we must implement *every* member of this interface
  619. End Sub
  620. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  621.     'VB requires that we must implement *every* member of this interface
  622. End Sub
  623. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  624.     Dim dpPeer As DPN_PLAYER_INFO
  625.     dpPeer = dpp.GetPeerInfo(lNewHostID)
  626.     If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then 'I am the new host
  627.         Me.Caption = Me.Caption & " (HOST)"
  628.     End If
  629. End Sub
  630. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  631.     'VB requires that we must implement *every* member of this interface
  632. End Sub
  633. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  634.     'VB requires that we must implement *every* member of this interface
  635. End Sub
  636. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  637.     'VB requires that we must implement *every* member of this interface
  638. End Sub
  639. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  640.     'All we care about in this demo is what msgs we receive.
  641.     Dim lMsg As Long, lOffset As Long
  642.     Dim oPacket As PacketInfo
  643.     With dpnotify
  644.     GetDataFromBuffer .ReceivedData, lMsg, LenB(lMsg), lOffset
  645.     Select Case lMsg
  646.     Case MSG_GamePacket 'We received a packet
  647.         'Update the UI showing we received the packet
  648.         GetDataFromBuffer .ReceivedData, oPacket, LenB(oPacket), lOffset
  649.         moReceived.Add CStr(dpnotify.idSender) & ";" & CStr(oPacket.lPacketID) & ";" & CStr(oPacket.lDataSize)
  650.     Case MSG_PacketReceive 'They received a packet we sent
  651.         'Update the UI showing we received the packet
  652.         GetDataFromBuffer .ReceivedData, oPacket, LenB(oPacket), lOffset
  653.         AppendText "Sent packet #" & CStr(oPacket.lPacketID) & " to " & GetName(dpnotify.idSender) & " - Size:" & CStr(oPacket.lDataSize)
  654.     End Select
  655.     End With
  656. End Sub
  657. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  658.     If dpnotify.hResultCode = DPNERR_TIMEDOUT Then 'our packet timed out
  659.         AppendText "Packet Timed Out... "
  660.     End If
  661.     'The send has completed, so DPlay no longer has a need for our
  662.     'buffer, so we can get rid of it now.
  663.     Erase moByte
  664.     Erase moBuf
  665.     'Allow the next send to happen
  666.     mfInSend = False
  667. End Sub
  668. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  669.     'This connection has been terminated.
  670.     If dpnotify.hResultCode = DPNERR_HOSTTERMINATEDSESSION Then
  671.         MsgBox "The host has terminated this session.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  672.     Else
  673.         MsgBox "This session has been lost.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  674.     End If
  675.     DPlayEventsForm.CloseForm Me
  676. End Sub
  677.